//
//  LineIndicatorView.m
//  OCDemo
//
//  Created by zhumuzhi on 2021/8/5.
//
//  线条指示器

#import "LineIndicatorView.h"

@interface LineIndicatorView ()

@property (nonatomic, strong) UIView *line;

@end

@implementation LineIndicatorView

#pragma mark - SetData
- (void)setIndeicatorColor:(UIColor *)indeicatorColor {
    _indeicatorColor = indeicatorColor;
    _line.backgroundColor = indeicatorColor;
}

- (void)setIndeicatorPercent:(CGFloat)indeicatorPercent {
    _indeicatorPercent = indeicatorPercent;
    
    CGFloat indeicatiorX = indeicatorPercent * (self.width-self.line.width);
    _line.x = indeicatiorX;
}

#pragma mark - Init
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        if (!self.indeicatorColor) {
            self.indeicatorColor = [UIColor blackColor];
        }
        [self addSubview:self.line];
    }
    return self;
}

#pragma mark - LazyGet
- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width*0.5, self.height)];
        [_line setViewCornerRadius:self.height * 0.5];
        _line.backgroundColor = self.indeicatorColor;
    }
    return _line;
}

@end
